package com.huaxin.device.dto.enums.schemes;

/**
 * 数据库表结构元数据定义（统一管理）
 * 使用嵌套枚举组织表与字段的层级关系
 * 支持多表管理，避免字段名冲突，提升可维护性
 */
public enum DatabaseSchema {

    // ==================== 表1: 环境检测仪数据表 ====================
    DEVICE_READINGS_ENVIRONMENT("device_readings_environment", "环境检测仪数据表") {
        @Override
        public Field[] getFields() {
            return DeviceReadingsEnvironmentField.values();
        }
    },

    // ==================== 表2: 断路器用电数据表 ====================
    DEVICE_READINGS_CIRCUIT_BREAKER("device_readings_circuit_breaker", "断路器用电数据表") {
        @Override
        public Field[] getFields() {
            return DeviceReadingsCircuitBreakerField.values();
        }
    };

    // ==================== 枚举抽象结构 ====================

    private final String tableName;
    private final String label;

    DatabaseSchema(String tableName, String label) {
        this.tableName = tableName;
        this.label = label;
    }

    public abstract Field[] getFields();

    public String getTableName() {
        return tableName;
    }

    public String getLabel() {
        return label;
    }


    public interface Field {
        String getFieldName();

        String getLabel();

        String getType();

        String getDescription();
    }

    // ==================== 嵌套枚举：各表字段定义 ====================

    /**
     * 表: device_readings_environment
     */
    enum DeviceReadingsEnvironmentField implements Field {
        TEMPERATURE("temperature", "温度", "DECIMAL(5,2)", "温度 (℃)"),
        HUMIDITY("humidity", "湿度", "DECIMAL(5,2)", "湿度 (%)"),
        SMOKE_DETECTED("smoke_detected", "烟雾检测", "BOOLEAN", "是否检测到烟雾"),
        CO_LEVEL("co_level", "一氧化碳浓度", "DECIMAL(6,2)", "一氧化碳浓度 (mg/m3)"),
        PM25("pm25", "PM2.5浓度", "INT", "PM2.5浓度 (ug/m3)"),
        NOISE_LEVEL("noise_level", "噪音", "DECIMAL(6,2)", "噪音 (dB)");

        private final String fieldName;
        private final String label;
        private final String type;
        private final String description;

        DeviceReadingsEnvironmentField(String fieldName, String label, String type, String description) {
            this.fieldName = fieldName;
            this.label = label;
            this.type = type;
            this.description = description;
        }

        @Override
        public String getFieldName() {
            return fieldName;
        }

        @Override
        public String getLabel() {
            return label;
        }

        @Override
        public String getType() {
            return type;
        }

        @Override
        public String getDescription() {
            return description;
        }
    }

    /**
     * 表: device_readings_circuit_breaker（新增）
     */
    enum DeviceReadingsCircuitBreakerField implements Field {
        VOLTAGE("voltage", "电压", "DECIMAL(10,2)", "电压 (V)"),
        CURRENT("current", "电流", "DECIMAL(10,2)", "电流 (A)"),
        POWER("power", "功率", "DECIMAL(10,2)", "功率 (kW)"),
        ENERGYTODAY("energyToday", "今日用电量", "DECIMAL(12,2)", "今日用电量 (kWh)");

        private final String fieldName;
        private final String label;
        private final String type;
        private final String description;

        DeviceReadingsCircuitBreakerField(String fieldName, String label, String type, String description) {
            this.fieldName = fieldName;
            this.label = label;
            this.type = type;
            this.description = description;
        }

        @Override
        public String getFieldName() {
            return fieldName;
        }

        @Override
        public String getLabel() {
            return label;
        }

        @Override
        public String getType() {
            return type;
        }

        @Override
        public String getDescription() {
            return description;
        }
    }
}